package com.fenghongzhang.lib_core.model


/**
 *@author Wcj
 *@description OpenApi返回数据
 *@date 2023/3/22 15:25
 */
open class BaseOpenApiModel(
    val code: String? = null,
    val context: String = "",
    var detail: String = "",
    val message: String = "",
    val partnerId: String = "",
    val requestNo: String = "",
    val service: String = "",
    var success: Boolean = false,
    val version: String = "",
    //val data:Any
) {
    //有些接口错误是detail是空 message才有错误信息
    fun setDetailIfEmpty() {
        if (detail.isEmpty()) detail = message
    }
}

data class ApplyAfterSalesResp(val orderCode: String?) : BaseOpenApiModel()

data class LoginOpenApiModel(
    val accessKey: String,
    val secretKey: String
) : BaseOpenApiModel()

data class SysLoginResponse(
    val accessKey: String?,
    val dataCode: String?,
    val expires: String?,
    val ext: Ext?,
    val mobile: String?,
    val nickname: String?,
    val phone: String?,
    val protocol: String?,
    val realName: String?,
    val refreshToken: String?,
    val secretKey: String?,
    val sessionInfo: String?,
    val sex: String?,
    val token: String?,
    val userType: String?,
) : BaseOpenApiModel()

class Ext


data class CommonListOpenApiModel<T>(
    val data: ArrayList<T>? = null,
    val datas: ArrayList<T>? = null,
    val mailConfInfo: ArrayList<T>? = null,
    val res: ArrayList<T>? = null,
    val sysAreaInfoList: ArrayList<T>? = null,
    val children: ArrayList<T>? = null,
    val memberShopAddressesList: ArrayList<T>? = null,
    val mallAdInfo: ArrayList<T>? = null,
    val statusDict: ArrayList<T>? = null,
    val companyDtoList: ArrayList<T>? = null,
    val tree: ArrayList<T>? = null,
    val goodsInfos: ArrayList<T>? = null,
    val cashDetailDtos: ArrayList<T>? = null,
    val groupInfoList: ArrayList<T>? = null,
    val allDetails: ArrayList<T>? = null,
) : BaseOpenApiModel()

data class PayCashResp(
    val orderCode: String? = null,
    val payCode: String? = null,
    val returnUrl: String? = null,
    val codeUrl: String? = null,
    val redirectUrl: String? = null,
    val payStatus: String? = null,// 支付状态(unpaid-待支付 paid-已支付)
    val payStatusDesc: String? = null,
    val orderType: String? = null,// 订单类型(normal-普通订单,point-积分订单)
    val orderTypeDesc: String? = null,
    val point: Int = 0
) : BaseOpenApiModel() {
    fun paySuccess(): Boolean = payStatus == "paid"
}

data class CommonBooleanOpenApiModel(
    val isFollowed: Boolean = false,
    val check: Boolean = false,
    val isSign: Boolean = false,
) : BaseOpenApiModel()

data class CommonPageOpenApiModel<T>(
    val rows: ArrayList<T>? = null,
    val totalPages: Int,
    val totalRows: Int
) : BaseOpenApiModel() {
    fun formatTotalRows(): String {
        return if (totalRows <= 0) ""
        else "(${
            when {
                totalRows > 990000 -> "99万+"
                totalRows > 100000 -> "10万+"
                totalRows in 10000..99999 -> {
                    val w = totalRows / 10000
                    "${w}万+"
                }
                else -> totalRows.toString()
            }
        })"
    }
}

data class CommonDataOpenApiModel<T>(
    val data: T? = null,
    val num: T? = null,
    val mallGoodsInfoInfo: T? = null,
    val createDto: T? = null,
    val shippingPrice: T? = null,
    val mailActivityInfo: T? = null,
    val h5Address: T? = null,
    val url: T? = null,
) : BaseOpenApiModel()

data class EvaluateInfoOpenApiModel(
    val bad: Int = 0,
    val good: Int = 0,
    val image: Int = 0,
) : BaseOpenApiModel() {
    fun formatBad(): String = if (bad > 10000) "1万+" else bad.toString()
    fun formatGood(): String = if (good > 10000) "1万+" else good.toString()
    fun formatImg(): String = if (image > 10000) "1万+" else image.toString()
}

data class CommonSingleOpenApiModel(
    val num: Int = 0,
    val state: Boolean = false
) : BaseOpenApiModel()

